package com.sure.supermarketserver.stock.manage.impl;

import com.sure.supermarketserver.common.Utils;
import com.sure.supermarketserver.stock.manage.BranchName;
import com.sure.supermarketserver.stock.manage.Goods;
import com.sure.supermarketserver.stock.manage.GoodsDto;
import com.sure.supermarketserver.stock.manage.GoodsService;
import com.sure.supermarketserver.stock.manage.dao.GoodsDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class GoodsServiceImpl implements GoodsService {

    @Resource
    private GoodsDao goodsDao;

    @Override
    public Map<String, Object> findGoodsList(GoodsDto goodsDto) {
        List<String> goidlist = goodsDao.getGoods();
        for (int i = 0; i < goidlist.size(); i++) {
            System.out.println(goidlist.get(i));
            goodsDao.checkGoodsRemark(goidlist.get(i));
        }
        return Utils.getPage(goodsDto, () -> goodsDao.findGoodsList(goodsDto));
    }

    @Override
    public Map<String, Object> findGoodsDetails(GoodsDto goodsDto) {
        return Utils.getPage(goodsDto, () -> goodsDao.findGoodsDetails(goodsDto));
    }

    @Override
    public void execGoods(String id) {

        goodsDao.execGoodsList(id);
    }

    @Override
    public void updGoods(GoodsDto dto) {
        goodsDao.updGoodsFA(dto);
        goodsDao.updGoodsCH(dto);
    }

    @Override
    public List<BranchName> findBranchList() {
        List<BranchName> branchList = goodsDao.findBranchList();
        return branchList;
    }
}
